package com.ruoyi.web.controller.veterinary;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.veterinary.domain.VetManufacturer;
import com.ruoyi.veterinary.service.IVetManufacturerService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 药品厂家Controller
 * 
 * @author ruoyi
 * @date 2024-01-19
 */
@RestController
@RequestMapping("/veterinary/manufacturer")
public class VetManufacturerController extends BaseController
{
    @Autowired
    private IVetManufacturerService vetManufacturerService;

    /**
     * 查询药品厂家列表
     */
    @PreAuthorize("@ss.hasPermi('veterinary:manufacturer:list')")
    @GetMapping("/list")
    public TableDataInfo list(VetManufacturer vetManufacturer)
    {
        startPage();
        List<VetManufacturer> list = vetManufacturerService.selectVetManufacturerList(vetManufacturer);
        return getDataTable(list);
    }

    /**
     * 查询所有正常状态的厂家列表（用于下拉选择）
     */
    @GetMapping("/active")
    public AjaxResult getActiveList()
    {
        List<VetManufacturer> list = vetManufacturerService.selectActiveManufacturerList();
        return success(list);
    }

    /**
     * 导出药品厂家列表
     */
    @PreAuthorize("@ss.hasPermi('veterinary:manufacturer:export')")
    @Log(title = "药品厂家", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VetManufacturer vetManufacturer)
    {
        List<VetManufacturer> list = vetManufacturerService.selectVetManufacturerList(vetManufacturer);
        ExcelUtil<VetManufacturer> util = new ExcelUtil<VetManufacturer>(VetManufacturer.class);
        util.exportExcel(response, list, "药品厂家数据");
    }

    /**
     * 获取药品厂家详细信息
     */
    @PreAuthorize("@ss.hasPermi('veterinary:manufacturer:query')")
    @GetMapping(value = "/{manufacturerId}")
    public AjaxResult getInfo(@PathVariable("manufacturerId") Long manufacturerId)
    {
        return success(vetManufacturerService.selectVetManufacturerByManufacturerId(manufacturerId));
    }

    /**
     * 新增药品厂家
     */
    @PreAuthorize("@ss.hasPermi('veterinary:manufacturer:add')")
    @Log(title = "药品厂家", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VetManufacturer vetManufacturer)
    {
        return toAjax(vetManufacturerService.insertVetManufacturer(vetManufacturer));
    }

    /**
     * 修改药品厂家
     */
    @PreAuthorize("@ss.hasPermi('veterinary:manufacturer:edit')")
    @Log(title = "药品厂家", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VetManufacturer vetManufacturer)
    {
        return toAjax(vetManufacturerService.updateVetManufacturer(vetManufacturer));
    }

    /**
     * 删除药品厂家
     */
    @PreAuthorize("@ss.hasPermi('veterinary:manufacturer:remove')")
    @Log(title = "药品厂家", businessType = BusinessType.DELETE)
	@DeleteMapping("/{manufacturerIds}")
    public AjaxResult remove(@PathVariable Long[] manufacturerIds)
    {
        return toAjax(vetManufacturerService.deleteVetManufacturerByManufacturerIds(manufacturerIds));
    }
}